package com.project.base.baseproject.ModelManager.IdentityManager;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

import com.project.base.baseproject.AppCustoms.MyApplication.MyApplication;
import com.project.base.baseproject.ModelManager.Models.Identity;

/**
 * Created by mac on 2016/11/25.
 */
//登陆信息管理器
public class IdentityManager {
    //sharedPreferences
    private SharedPreferences sharedPreferences = null;
    //identity info
    public Identity identity = new Identity();
    private static IdentityManager instance = null;
    public static IdentityManager manager() {
        if(null == instance)
            instance = new IdentityManager();
        return instance;
    }
    //从本地获取登录信息
    public void readAuthorizeData() {
        sharedPreferences = MyApplication.getInstance().getSharedPreferences("Identity_Manager_BaseProject", Context.MODE_PRIVATE);
        identity.user_guid = sharedPreferences.getString("user_guid","");
        identity.firstUseSoft = sharedPreferences.getInt("firstUseSoft",1);
        identity.accessToken = sharedPreferences.getString("accessToken","");
    }
    //保存登录信息到本地
    public void saveAuthorizeData() {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("user_guid", identity.user_guid);
        editor.putInt("firstUseSoft", identity.firstUseSoft);
        editor.putString("accessToken", identity.accessToken);
        editor.apply();//commit()也可以达到效果，但是apply()速度更快
    }
}


